<?php

class LoginModel extends Model{
	//定义表名
	public $table = 'admin';
	//验证
	public $validate = array(
		array('adminname','','用户名',2,3),
		array('password','','密码不能为空',2,3)
	);
	
	public function login_validate(){
		if(!$this->create()) return false;
		
		$adminname = Q('post.adminname');
		$password  = Q('post.password','','md5');
		
		$data = $this->where(array('adminname'=>$adminname))->find();
		if(!$data || $password != $data['password']){
			$this->error = '用户名或者密码错误';
			return false;
		}
		return $data;
	}
	
	
}
